package com.donghua.util;

import lombok.Data;

@Data
public class Result<T> {

    /**
     * 返回码
     */
    private Integer code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;
    public static <T> Result<T> ok() {
        return restResult(0, null, null);
    }
    public static <T> Result<T> ok(Integer code, String message) {
        return restResult(code, message, null);
    }
    public static <T> Result<T> ok(Integer code, String message, T data) {
        return restResult(code, message, data);
    }


    private static <T> Result<T> restResult(Integer code, String message, T data) {
        Result<T> apiResult = new Result<>();
        apiResult.setCode(code);
        apiResult.setMessage(message);
        apiResult.setData(data);
        return apiResult;
    }
}
